/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.niedziela12.pai.ejb.reservation.facades;

import com.niedziela12.pai.ejb.AbstractFacade;
import com.niedziela12.pai.ejb.entities.Reservation;
import com.niedziela12.pai.ejb.entities.User;
import java.util.List;
import javax.ejb.Stateless;
import javax.ejb.TransactionAttribute;
import javax.ejb.TransactionAttributeType;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

/**
 *
 * @author Kamil
 */
@Stateless
@TransactionAttribute(TransactionAttributeType.MANDATORY)
public class ReservationFacade extends AbstractFacade<Reservation> implements ReservationFacadeLocal {
    @PersistenceContext(unitName = "com.niedziela12.pai.ejb")
    private EntityManager em;

    @Override
    protected EntityManager getEntityManager() {
        return em;
    }

    public ReservationFacade() {
        super(Reservation.class);
    }

    @Override
    public User findCurrentUser(String login){
        return (User)em.createQuery("SELECT k FROM user k WHERE k.login = '"+login +"'").getSingleResult();
    }

    @Override
    public List<Reservation> findUserReservation(String login) {
        return em.createNamedQuery("Reservation.reservationForUser").setParameter("login", login).getResultList();
    }
    
}
